package com.study.Thread;

/**
 * 继承Thread类重写run方法,并执行start()方法
 */
public class EXThread {

    public static void main(String[] args){
        Integer i=0;
        while (i<6){
            i++;
            new SaleThread("thread"+i.toString()).start();
        }

    }

}
class SaleThread extends Thread{
   private static int i=1000;
   private String name="";
   boolean b = true;
    public SaleThread(String s) {
        name=s;
    }

    @Override
    public void run() {
        while (b) {
                synchronized ("abcdefj") {
                    if (i<=0)
                    {
                        b=false;
                        return;
                    }
                    i--;
                    System.out.println(name + "售票一张，剩余" + i);
                    try {
                        sleep(2);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
        }
    }
}
